﻿using UtilityExtensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using BOL;
using System.Data.Linq;
using System.Data.SqlClient;
using Website.Logger;

namespace UILGestion.Admin.Almacenes
{
    public partial class AlmacenListForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                try
                {
                    menuCtrl1.loadMenuSeguridad();
                    FormatForm();


                }
                catch (SqlException sqlex)
                {
                    WebServerSideSqlError.Log(sqlex);
                    ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                     "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);


                }
                catch (Exception ex)
                {
                    WebServerSideError.Log(ex);
                    ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                     "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);

                }


            }
        }

        private void Find()
        {
            //valores de parametro

            //AlmacenBL bol = new AlmacenBL();

            //entityListGridView.DataSource = bol.GetAlmacenList(idEmpresa); 
            //entityListGridView.DataBind();

        }

        private void FormatForm()
        {
            ShowAllComboBox();
            //restricionesForm();
           // Find();
            //estadistica();

         
        }
        protected void ShowAllComboBox()
        {
            empresaDDL.DataTextField = "descripcion";
            empresaDDL.DataValueField = "idInternal";
            empresaDDL.DataSource = new ListValueBL().GetEmpresas();
            empresaDDL.DataBind();

            proyectoDDL.DataTextField = "descripcion";
            proyectoDDL.DataValueField = "idInternal";
           


          

        }

        private void loadProyecto()

        {
            proyectoDDL.DataSource = new ListValueBL().GetProyectoComprasXEmpresa(empresaDDL.SelectedValue.ToInt());
            proyectoDDL.DataBind();
        }

        protected void nuevoButton_Click(object sender, EventArgs e)
        {

            Response.Redirect("AlmacenInsertForm.aspx?type=A", true);
        }


        protected void obraDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                //Find();
                //estadistica();
            }
            catch (SqlException sqlex)
            {
                WebServerSideSqlError.Log(sqlex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);


            }
            catch (Exception ex)
            {
                WebServerSideError.Log(ex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);

            }

        }

        protected void empresaDDL_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                loadProyecto();
            }
            catch (SqlException sqlex)
            {
                WebServerSideSqlError.Log(sqlex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);


            }
            catch (Exception ex)
            {
                WebServerSideError.Log(ex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);

            }
            
        }
       
    }
}